# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time      :2022/8/2 0002 0:52
# @Author    :jiaxuesong


#导包
import os
from configparser import ConfigParser

#定义读取配置文件类
class ReadConfig(object):
    #定义初始化方法，获取配置文件存放路径
    def __init__(self):
        self.file_path = os.path.dirname(os.path.dirname(__file__)) + r'/config.ini'
        # 实例化调用configparser
        self.conf = ConfigParser()
        # 读取配置文件的全部内容
        self.conf.read(self.file_path)

    # 定义对外调用方法，获取section和option
    def get_config(self, section, option = 'all'):
        if option == 'all':
            return self.conf.items(section)
        else:
            return self.conf.get(section, option)


if __name__ == '__main__':
    re = ReadConfig()
    print(re.get_config('APP', 'deviceName'))